package Com.javaserver.servlet;

import Com.javaserver.bean.rewland;
import Com.javaserver.dao.rewlandserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/rewdele")
public class rewlanddeleserverlet extends HttpServlet {
    rewlandserver rewd=new rewlandserver();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
          doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String dele=req.getParameter("dele");
        rewland rew=new rewland();
        rew.setP_id(Integer.valueOf(dele));
        if (rewd.rewdele(rew)==false){
            List<rewland> list=rewd.rewlist(1);
            req.getSession().setAttribute("rewdele",list);
            req.getSession().setAttribute("msg","删除失败");
            resp.sendRedirect(req.getContextPath()+"/rewland.jsp");
        }else {
            List<rewland> list=rewd.rewlist(1);
            req.getSession().setAttribute("rewlist",list);
            req.getSession().setAttribute("msg","删除成功！");
            resp.sendRedirect(req.getContextPath()+"/rewland.jsp");
        }
    }
}
